/*****************************************************************
* REPLICATION CODES: AMERICAN DREAM
*
* Master Do File
*
* Purpose:
*   This is the master do file that sets up all paths, loads any 
*   required user-written packages, and then executes the full series 
*   of scripts to clean the data, generate figures, produce tables, 
*   and compute calibration targets for the American Dream replication.
*
* Contents:
*   - Package Installation: Installs any needed user-written Stata commands.
*   - Global Path Setup: Defines all necessary global file paths 
*     (raw data, output directories, etc.) based on user's local setup.
*   - Data Cleaning:
*       - clean_census_tract.do: Cleans census tract-level data.
*       - clean_metro.do: Cleans metro-level data.
*   - Figures:
*       - all_figs.do: Generates all figures (e.g., Theil indices, 
*         inequality, segregation, etc.).
*   - Calibration Targets:
*       - calibration_targets.do: Classifies neighborhoods based on
*         income shares and computes statistics (moments) to calibrate
*         the model.
*   - Regression & Summary Tables:
*       - reg_gini_dissim.do: Creates regression tables (Tables 11 to 14)
*         and summary outputs, saved to the output folder.
*
* Usage:
*   - Update the global path to match your local directory structure.
*   - Run this file in Stata to replicate all steps.
*
*****************************************************************/

/*---------------------------------------------------------------
   Package Installation
---------------------------------------------------------------*/
ssc install _GWTMEAN  // provides egen weighted mean command

/*---------------------------------------------------------------
   Global Path Setup
---------------------------------------------------------------*/
global path "JPE_Replication_Final\"  // Set the path to the main replication folder 

global output "$path/Output"
global raw_data "$path/Raw_Data"

/*---------------------------------------------------------------
   Data Cleaning
---------------------------------------------------------------*/
do "$path/Codes/Data_Cleaning/clean_census_tract.do"
do "$path/Codes/Data_Cleaning/clean_metro.do"

/*---------------------------------------------------------------
   Figures
---------------------------------------------------------------*/
do "$path/Codes/Figures/all_figs.do"

/*---------------------------------------------------------------
   Calibration Targets
---------------------------------------------------------------*/
do "$path/Codes/Calibration/calibration_targets.do"  
* Output is saved at "$output/calibration_targets.xlsx"

/*---------------------------------------------------------------
   Regression & Summary Tables
---------------------------------------------------------------*/
do "$path/Codes/Regressions/reg_gini_dissim.do"  
* Makes tables 11 to 14 and saves them in the output folder
